﻿@{
    /* 带table 以及增删查改的 的layui页面 */
    ViewBag.Title = "_LayuiTableEdit";
    Layout = "~/Views/Shared/_LayuiTable.cshtml";
}
<script>
    var otherEventHandle, detailHandle, delHandle, editHandle;
    var EditModel;
    var restEditModel;
    function setEditModel(obj) {
        if (obj) EditModel = obj;
    }
    addLayuiUseEvent(function () {
        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                detailHandle(data);
                //layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                console.log(obj);
                delHandle(data);
            } else if (obj.event === 'edit') {
                //layer.alert('编辑行：<br>' + JSON.stringify(data))
                editHandle(data);
            } else {                
                otherEventHandle(data, obj.event);
            }
        });
    });
    function showEditView(title, url) {
        var index = layer.open({
            title: title,
            type: 2,
            content: url,
            area: ['300px', '300px'],
            maxmin: true
        });
        layer.full(index);
    }
    //删除
    delHandle = function (rowData) {
        layer.confirm('真的删除么', function (index) {
            jqJsonPost("@ViewBag.DelUrl",
                { Id : rowData.Id},
                function (data) {
                    layer.msg(data.msg);
                    if (data.code == 0) {
                        tableReload();
                    }
                });
            return false;
        });
    }
    //编辑
    editHandle = function (rowData) {
        if (restEditModel) {
            EditModel = restEditModel(rowData);
        } else {
            EditModel = rowData;
        }
        var url = "Edit?type=update";
        showEditView("编辑", url);
    }
    function add() {
        EditModel = undefined;
        var url = "Edit?type=add";
        showEditView("新增", url);
    }
</script>
@RenderBody()